/**
 * Created by smallcoder on 2016/3/3.
 */
var Promise = require('promise');
var logger = require('log4js').getLogger('memberLogService');
var comm = require('../../utils/commonUtils');
var mailUtil = require('../../utils/mail');
var memberLogDao = require('../dao/MemberLogDao');
var memberLogService = {};

memberLogService.saveLog = function (memberId,articleId,type) {
    var memberLog = {};
    memberLog.memberId = memberId;
    memberLog.targetId = articleId;
    memberLog.type = type;

    return memberLogDao.getByParams(memberLog,'id').then(function (logs) {
        if(logs&&logs.length>0){
            var log = logs[0];
            log.logTime = new Date();
            log.updateTime = new Date();
            return memberLogDao.update(log);
        }else{
            memberLog.logTime = new Date();
            memberLog.createTime = new Date();
            return memberLogDao.save(memberLog);
        }
    })

}


module.exports = memberLogService;